<template>
	<view class="beijingse" style="padding: 1rpx 30rpx 30rpx;">
		<view class=" block margin_top mainpadding radius flexbetween" v-for="item in list.data" :key="item.mj_price">
			<view class="flexleft">
				<view class=" margin_right4">
					<view class="strongtext xiaocheng fonweight">￥
						<text class="sishi xiaocheng fonweight">{{item.price}}</text>
					</view>
					<view class="xiaohui strongtext margin_top2">满{{item.mj_price}}可用</view>
				</view>
				<view class="dqline margin_right"></view>
				<view class="">
					<view class="zhonghei sanshier fonweight">{{item.name}}</view>
					<view class="strongtext xiaohui margin_top2">领取后{{item.days}}天内可用</view>
				</view>
			</view>
			<!-- 已领取 -->
			<view class="ylhbtn flexcenter" v-if="item.is_get==1">已领取</view>
			<!-- 未领取 -->
			<view class="wlhbtn flexcenter" v-if="item.is_get==0" @click="lingqu(item)">立即领取</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid: ""
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.init()
		},
		methods: {
			lingqu(item){
				httpRequest.request('/api/user/getCoupon', 'GET', {
					id:item.id
				}, false, false, false).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						item.is_get = 1
					}
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/user/ptCouponIndex', 'GET', {
					page: page || 1,
					limit: _this.limit,
					shop_id:0,
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wlhbtn {
		width: 132rpx;
		height: 49rpx;
		background: rgba(255, 133, 5, 0.1);
		border-radius: 4rpx 4rpx 4rpx 4rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		border: 1rpx solid #FF8505;
	}

	.ylhbtn {
		width: 132rpx;
		height: 49rpx;
		background: rgba(156, 156, 156, 0.1);
		border-radius: 4rpx 4rpx 4rpx 4rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #9C9C9C;
		border: 1rpx solid #9C9C9C;
	}

	.dqline {
		width: 1rpx;
		height: 52rpx;
		background-color: #999999;
	}

	.block {
		background: #FBF6F1;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}
</style>